package com.quick.framework.domain.server;


import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * 內存相关信息
 *
 * @Author: 吃素不吃肉
 * @Date: Tue Jul 25 14:14:44 CST 2023
 */
public class Mem {
    /**
     * 内存总量
     */
    private double total;

    /**
     * 已用内存
     */
    private double used;

    /**
     * 剩余内存
     */
    private double free;

    public double getTotal() {
        return new BigDecimal(String.valueOf(total)).divide(new BigDecimal(String.valueOf(1024 * 1024 * 1024)), 2, RoundingMode.UP).doubleValue();
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public double getUsed() {
        return new BigDecimal(String.valueOf(used)).divide(new BigDecimal(String.valueOf(1024 * 1024 * 1024)), 2, RoundingMode.UP).doubleValue();
    }

    public void setUsed(long used) {
        this.used = used;
    }

    public double getFree() {
        return new BigDecimal(String.valueOf(free)).divide(new BigDecimal(String.valueOf(1024 * 1024 * 1024)), 2, RoundingMode.UP).doubleValue();
    }

    public void setFree(long free) {
        this.free = free;
    }

    public double getUsage() {
        return new BigDecimal(String.valueOf(total - free)).divide(new BigDecimal(String.valueOf(total)), 4, RoundingMode.UP).multiply(new BigDecimal("100")).doubleValue();
    }
}
